package com.love.user.controller;

import com.love.common.entity.user.User;
import com.love.common.util.RespUtil;
import com.love.common.vo.RespResultVO;
import com.love.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户controller
 *
 * @author sunbo
 * @date 2021/5/10 下午5:45
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private IUserService userService;

    @Value("${server.port}")
    private String port;

    // 注入配置文件上下文
    @Autowired
    private ConfigurableApplicationContext applicationContext;

    @GetMapping(value = "/test/{name}")
    public String test(@PathVariable String name) {
        return "success! hello: " + name + " i am from port " + port;
    }

    // 从上下文中读取配置
    @GetMapping(value = "/hi")
    public String sayHi() {
        return "Hello " + applicationContext.getEnvironment().getProperty("user.name");
    }

    @GetMapping(value = "one", produces = "application/json; charset=UTF-8")
    public RespResultVO selectById(Integer userId) {
        return RespUtil.success(userService.selectById(userId));
    }

}
